package rad.framework.mda.generator.template.test.java.seam;

import java.util.*;
import org.eclipse.uml2.uml.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class SeamJUnit
{
  protected static String nl;
  public static synchronized SeamJUnit create(String lineSeparator)
  {
    nl = lineSeparator;
    SeamJUnit result = new SeamJUnit();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";";
  protected final String TEXT_3 = NL;
  protected final String TEXT_4 = NL + NL + "/**" + NL + " * Unit tests for the ";
  protected final String TEXT_5 = " Seam components." + NL + " * " + NL + " * @author ";
  protected final String TEXT_6 = NL + " * @generated" + NL + " */" + NL + "public class ";
  protected final String TEXT_7 = "SeamTest extends SeamCrudTest<";
  protected final String TEXT_8 = "> {" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic ";
  protected final String TEXT_9 = "SeamTest(String name) {" + NL + "\t\tsuper(name, \"java:/";
  protected final String TEXT_10 = "\", 20);" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic static Test suite() {" + NL + "\t\tTestSuite suite = new TestSuite();" + NL + "\t\tsuite.addTest(new ";
  protected final String TEXT_11 = "SeamTest(\"testCrud\"));" + NL + "\t\treturn new Bootstrap(suite);" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic void initData(EntityManager em) {" + NL + "\t\t// test data. change or remove as appropriate";
  protected final String TEXT_12 = NL + "\t\taddValue(\"";
  protected final String TEXT_13 = "\", \"";
  protected final String TEXT_14 = "\", ";
  protected final String TEXT_15 = ");";
  protected final String TEXT_16 = NL + "\t\taddValue(\"";
  protected final String TEXT_17 = "\", Boolean.TRUE, ";
  protected final String TEXT_18 = ");";
  protected final String TEXT_19 = NL + "\t\taddValue(\"";
  protected final String TEXT_20 = "\", truncateDate(new Date()), ";
  protected final String TEXT_21 = ");";
  protected final String TEXT_22 = NL + "\t\taddValue(\"";
  protected final String TEXT_23 = "\", new Date(), ";
  protected final String TEXT_24 = ");";
  protected final String TEXT_25 = NL + "\t\taddValue(\"";
  protected final String TEXT_26 = "\", new BigDecimal(0), ";
  protected final String TEXT_27 = ");";
  protected final String TEXT_28 = NL + "\t\taddValue(\"";
  protected final String TEXT_29 = "\", new Double(0), ";
  protected final String TEXT_30 = ");";
  protected final String TEXT_31 = NL + "\t\taddValue(\"";
  protected final String TEXT_32 = "\", new Double(0), ";
  protected final String TEXT_33 = ");";
  protected final String TEXT_34 = NL + "\t\taddValue(\"";
  protected final String TEXT_35 = "\", new Long(0), ";
  protected final String TEXT_36 = ");";
  protected final String TEXT_37 = NL + "\t\taddValue(\"";
  protected final String TEXT_38 = "\", null, ";
  protected final String TEXT_39 = ");";
  protected final String TEXT_40 = NL + "\t\t" + NL + "\t\t// test drop-dow menu lists ";
  protected final String TEXT_41 = NL + "\t\taddList(\"";
  protected final String TEXT_42 = "ComboBox.filter('')\");";
  protected final String TEXT_43 = NL + "\t\taddList(\"";
  protected final String TEXT_44 = "ComboBox.filter('')\");";
  protected final String TEXT_45 = NL + "\t\taddList(\"";
  protected final String TEXT_46 = "Picker.available\");";
  protected final String TEXT_47 = NL + "\t\taddList(\"";
  protected final String TEXT_48 = "Picker.available\");";
  protected final String TEXT_49 = NL + "\t\taddList(\"filter";
  protected final String TEXT_50 = "s('')\");";
  protected final String TEXT_51 = NL + "\t\taddList(\"filter";
  protected final String TEXT_52 = "s('')\");";
  protected final String TEXT_53 = NL + NL + "\t\t// test charts";
  protected final String TEXT_54 = NL + "\t\taddChart(\"";
  protected final String TEXT_55 = "PieChart\");";
  protected final String TEXT_56 = "   ";
  protected final String TEXT_57 = NL + "\t\taddChart(\"";
  protected final String TEXT_58 = "PieChart\");";
  protected final String TEXT_59 = "   " + NL + "" + NL + "\t}" + NL + "}";
  protected final String TEXT_60 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    org.eclipse.uml2.uml.Class uml2Class = (org.eclipse.uml2.uml.Class) argument;org.eclipse.uml2.uml.Package uml2Package = uml2Class.getPackage();
    ImportManager importManager=null;
    if (NameHelper.getQualifiedName(uml2Package) != null) {
    importManager = ImportHelper.makeImportManager(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_1);
    stringBuffer.append(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_2);
    } else {
    importManager = ImportHelper.makeImportManager("");
    }
    stringBuffer.append(TEXT_3);
    importManager.addImport("junit.framework.Test");
    importManager.addImport("junit.framework.TestSuite");
    importManager.addImport("javax.persistence.EntityManager");
    importManager.addImport("rad.framework.testing.SeamCrudTest");
    importManager.addImport("rad.framework.embedded.Bootstrap");
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_4);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_5);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_6);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_9);
    stringBuffer.append(uml2Class.getModel().getName());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_11);
    for (Iterator<Property> i=ClassHelper.getAllSimpleProperties(uml2Class); i.hasNext();) { Property property = i.next();
    if (!StereotypeHelper.isStereotypeApplied(property, "javax.persistence.Id")) {
    if (TypeHelper.isStringType(property.getType()) || TypeHelper.isText(property)) {
    stringBuffer.append(TEXT_12);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_15);
     } else if (TypeHelper.isBoolean(property)) {
    stringBuffer.append(TEXT_16);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_17);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_18);
     } else if (TypeHelper.isDate(property)) {
    importManager.addImport("java.util.Date");
    stringBuffer.append(TEXT_19);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_20);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_21);
     } else if (TypeHelper.isTimestamp(property) || TypeHelper.isTime(property)) {
    importManager.addImport("java.util.Date");
    stringBuffer.append(TEXT_22);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_23);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_24);
     } else if (TypeHelper.isCurrency(property)) {
    stringBuffer.append(TEXT_25);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_26);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_27);
     } else if (TypeHelper.isDecimal(property)) {
    stringBuffer.append(TEXT_28);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_29);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_30);
     } else if (TypeHelper.isPercentage(property)) {
    stringBuffer.append(TEXT_31);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_32);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_33);
     } else if (TypeHelper.isInteger(property)) {
    stringBuffer.append(TEXT_34);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_35);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_36);
    } else {
    stringBuffer.append(TEXT_37);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_38);
    stringBuffer.append(property.getDefault() != null);
    stringBuffer.append(TEXT_39);
    }
    }}// TODO embeddeds
    stringBuffer.append(TEXT_40);
    for (Iterator<Property> i=ClassHelper.getAllManyToOneProperties(uml2Class); i.hasNext();) { Property property = i.next();
    if (StereotypeHelper.isStereotypeApplied(property, StereotypeHelper.M2O)) {
    stringBuffer.append(TEXT_41);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_42);
    }}
    for (Iterator<Property> i=ClassHelper.getAllOneToOneProperties(uml2Class); i.hasNext();) { Property property = i.next();
    stringBuffer.append(TEXT_43);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_44);
    }
    for (Iterator<Property> i=ClassHelper.getAllOneToManyProperties(uml2Class); i.hasNext();) { Property property = i.next();
    if (ClassHelper.isShared(property)) {
    stringBuffer.append(TEXT_45);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_46);
    }}
    for (Iterator<Property> i=ClassHelper.getAllManyToManyProperties(uml2Class); i.hasNext();) { Property property = i.next();
    stringBuffer.append(TEXT_47);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_48);
    }
    for (Iterator<Property> i=ClassHelper.getCompositeProperties(uml2Class); i.hasNext();) { Property property = i.next();
    for (Iterator<Property> j=ClassHelper.getAllManyToOneProperties((org.eclipse.uml2.uml.Class)property.getType()); j.hasNext();) { Property property2 = j.next();
    if ((property2.getOpposite() == null || !property2.getOpposite().isComposite()) && StereotypeHelper.isStereotypeApplied(property2, StereotypeHelper.M2O)) {
    stringBuffer.append(TEXT_49);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(NameHelper.getCapName(property2));
    stringBuffer.append(TEXT_50);
    }}
    for (Iterator<Property> j=ClassHelper.getCompositeProperties((org.eclipse.uml2.uml.Class)property.getType()); j.hasNext();) { Property property2 = j.next();
    for (Iterator<Property> k=ClassHelper.getAllManyToOneProperties((org.eclipse.uml2.uml.Class)property2.getType()); k.hasNext();) { Property property3 = k.next();
    if ((property3.getOpposite() == null || !property3.getOpposite().isComposite()) && StereotypeHelper.isStereotypeApplied(property3, StereotypeHelper.M2O)) {
    stringBuffer.append(TEXT_51);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(NameHelper.getCapName(property2));
    stringBuffer.append(NameHelper.getCapName(property3));
    stringBuffer.append(TEXT_52);
    }}}}
    stringBuffer.append(TEXT_53);
    for (Iterator<Property> i=EnumerationHelper.getAllEnumerations(uml2Class); i.hasNext();) { Property property = i.next();
    stringBuffer.append(TEXT_54);
    stringBuffer.append(NameHelper.getUncapName(property));
    stringBuffer.append(TEXT_55);
    }
    stringBuffer.append(TEXT_56);
    for (Iterator<Property> l=ClassHelper.getAllManyToOneProperties(uml2Class); l.hasNext();) { Property property = l.next();
    if (!ClassHelper.isComposite(property)) {
    stringBuffer.append(TEXT_57);
    stringBuffer.append(NameHelper.getUncapName(property));
    stringBuffer.append(TEXT_58);
    }}
    stringBuffer.append(TEXT_59);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_60);
    return stringBuffer.toString();
  }
}
